package com.tianji.remark.task;

import com.tianji.common.utils.CollUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.stream.Collectors;


/**
 * @author Xinxuan Zhuo
 * @version 2024/3/5
 * <p>
 *
 * </p>
 */

@Slf4j
@Component
@RefreshScope
public class ForLikedTimesCheckTaskBizType {

    @Value("${biztype.all}")
    private String BIZTYPE_ALL;

    private LinkedList<String> stack ;

    /**
     * 返回下一个业务类型并更新当前节点
     */
    public synchronized String next() {
        // 为空重新填满栈
        if (CollUtils.isEmpty(stack)) {
            String[] bizType = BIZTYPE_ALL.split(",");
            stack = Arrays.stream(bizType).collect(Collectors.toCollection(LinkedList::new));
        }
        return stack.removeLast();
    }


}
